package com.yyk.yiliao.ui.trade.minepwd;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.inputmethod.InputMethodManager;

import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.ui.trade.widget.PasswordInputView;
import com.yyk.yiliao.util.ToastUtil;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;

/**
 * 设置 找回密码 第一输入新密码
 */
public class SetInvestPasswordUpadteActivity extends BaseActivity {
    public static SetInvestPasswordUpadteActivity intance;
    @BindView(R.id.pwd_inputview)
    PasswordInputView pwdInputview;

    @Override
    public int getLayoutId() {
        return R.layout.activity_set_invest_password_upadte;
    }

    @Override
    public void initView() {
        initToolbar();
        initTextListenter();
    }

    @Override
    protected void onResume() {
        super.onResume();
        initRuanjianpan();
    }

    /**
     * 自动弹出键盘输入框
     */
    private void initRuanjianpan() {
        pwdInputview.setFocusable(true);
        pwdInputview.setFocusableInTouchMode(true);
        pwdInputview.requestFocus();
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
                           public void run() {
                               InputMethodManager inputManager =
                                       (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                               inputManager.showSoftInput(pwdInputview, 0);
                           }
                       },
                200);
    }


    private void initTextListenter() {
        pwdInputview.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() > 5) {
                    String string = pwdInputview.getText().toString();
//                    ToastUtil.showShort(mActivity, string);
                    Bundle bundle = new Bundle();
                    bundle.putString("pwd", string);

//                    startAct(SetInvestPasswordUpadte2Activity.class, bundle);
                    //这种跳转 toast时间短,因为toast互相顶掉了
                    Intent intent = new Intent(SetInvestPasswordUpadteActivity.this, SetInvestPasswordUpadte2Activity.class);
                    intent.putExtra(BUNDLE, bundle);
                    startActivityForResult(intent, REQUEST_CODE);

                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

    }

    private void initToolbar() {
        setBackArrow();
        setTitle("修改交易密码");
    }

    @Override
    public void initData() {
        intance=this;
    }

    int REQUEST_CODE = 1;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 2) {
            if (requestCode == REQUEST_CODE) {

                Bundle extras = data.getExtras();
                String kong = extras.getString("");
                pwdInputview.setText("");
                ToastUtil.showShort(mActivity, kong);

            }
        }

    }
}
